package views;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.JTextField;

import multiformat.Calculator;

/**
 * 
 * @author Alexander Jeurissen, Dustin Meijer
 *
 */

public class OperandView extends JPanel implements ActionListener {

	private static final long serialVersionUID = 1L;

	private Calculator calculator;
	
	private String strFirstOperand;
	private String strSecondOperand;
	
	private JTextField txtFirst;
	private JTextField txtSecond;
	
	public OperandView() {
		
		this.setLayout(	new GridLayout(1,3)	);
		
		//initialize textfields
		this.txtFirst = new JTextField("0.0");
		this.txtSecond = new JTextField("0.0");
		
		//make the textfields uneditable
		this.txtFirst.setEditable(false);
		this.txtSecond.setEditable(false);
		
		//change the background color of Operand textfields back to white
		this.txtFirst.setBackground(Color.white);
		this.txtSecond.setBackground(Color.white);
		
		
		//add textfields to panel
		this.add(txtFirst);
		this.add(txtSecond);
		
		this.validate();
		//make panel visible
		this.setVisible(true);

		
	}
	
	public void actionPerformed( ActionEvent e ) {
		calculator = (Calculator) e.getSource();
		  
		this.strFirstOperand = calculator.firstOperand();
		this.strSecondOperand = calculator.secondOperand();
		    
		txtFirst.setText(strFirstOperand);
		txtSecond.setText(strSecondOperand);    
	}
	 

		
}
